package it.kion.util.ui.umenumanager2.listener;

import it.kion.util.ui.umenumanager2.model.Item;
import it.kion.util.ui.umenumanager2.views.TreeObject;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Text;

public class MenuSelectionChangeListener implements ISelectionChangedListener {

	private Text infoPane;

	public MenuSelectionChangeListener(Text infoPane) {
		this.infoPane = infoPane;
	}

	public void selectionChanged(SelectionChangedEvent event) {
		if ((event.getSelectionProvider() instanceof TreeViewer)) {
			TreeViewer treeViewer = (TreeViewer) event.getSelectionProvider();
			ISelection selection = treeViewer.getSelection();
			Object obj = ((IStructuredSelection) selection).getFirstElement();
			if (obj instanceof TreeObject) {
				TreeObject to = (TreeObject) obj;
				infoPane.setText("");
				if(to.getWrappedObj() instanceof Item){
					Item item = (Item)to.getWrappedObj();
					infoPane.append("BP: " + item.getBusinessProcessClass().trim());
					infoPane.append(String.valueOf('\n'));
					infoPane.append("View: " + item.getView().trim());
				}
			}
		}
	}

}
